<?php


/**
 * Rappresenta una coordinata GPS
 * @author Giuseppe
 *
 */
class GPS {
	
	
	private $lat;
	private $lon;
	
	private static $RAGGIO_QUADRATICO_MEDIO = 6372.795477598;
	
	
	function __construct($lat, $lon) {
		$this->lat = $lat;
		$this->lon = $lon;
	}
	
	function getLat() {
		return $this->lat;
	}
	
	
	function getLon() {
		return $this->lon;
	}
	
	function distanceFrom ($gpsPoint) {  
  
            
  
          $decLatB = $gpsPoint->getLat();
          $decLonB = $gpsPoint->getLon();  

          if (($decLatB==$this->lat) && ($decLonB==$this->lon))
          	return 0;
          
          $radLatA = pi() * $this->lat / 180;  
  
          $radLonA = pi() * $this->lon / 180;  
  
          $radLatB = pi() * $decLatB / 180;  
  
          $radLonB = pi() * $decLonB / 180;  
  
          $phi = abs($radLonA-$radLonB);

          $P = acos (  
  
              (sin($radLatA) * sin($radLatB)) +  
  
              (cos($radLatA) * cos($radLatB) * cos($phi))  
  
          );  
  
          return $P * 6372.795477598;  
  
}  
	
}




?>